package com.boost.socialNetwork.client;

import com.boost.socialNetwork.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.reveregroup.gwt.facebook4gwt.Facebook;


/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class SocialNetwork implements EntryPoint {
		
	private final UserServiceAsync bootstrapService = GWT
	.create(UserService.class);		
	
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {					
		Facebook.init("112457388850276");
		bootstrapService.getConnected(new AsyncCallback<String>() {

			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onSuccess(String result) {
				HistoryManager.addValueChangeHandler(new ValueChangeHandler<String>() {

					@Override
					public void onValueChange(ValueChangeEvent<String> event) {
						System.out.println("on value change");
						HistoryManager.HistoryChange(event);
					}
				});
				
				if (result == null) {
					HistoryManager.newHistory("PageLogin");
					
				} else {
					bootstrapService.getCurrentPage(new AsyncCallback<String>() {
						public void onFailure(Throwable caught) {
							
						}
						
						public void onSuccess(String result) {
							HistoryManager.fireCurrentHistoryState();
//							System.out.println("uuuuuuuuuuu" + result);
//							if (result.equals("PageHome")) {								
//								HistoryManager.newHistory("PageHome");
//								System.out.println("equals home page");
//							} else {
//								if (result.equals("PageIdea")) {
//									HistoryManager.newHistory("PageIdea");
//								} else {
//									if (result.equals("PageReg")) {
//										HistoryManager.newHistory("PageReg");
//									} else {
//										if (result.equals("PageIdeaEntry")) {
//											HistoryManager.newHistory("PageIdeaEntry");
//										}
//									}
//								}
//							}
						}
					
					});
					
				}
			}
});

		
	}
	
}
